import { BasicDrawer, useDrawerInner } from "@/components/Drawer";
import { useFetchHistoryData, History } from "@/components/ViewComponents/History/index";
import { useTranslation } from "react-i18next";
import { patientSynthesisList } from "@/api/SecondmentDictionary";
import { useState } from "react";
const DetailDrawer = (props: { register: Fn }) => {
	const { t } = useTranslation();
	const [isHistory, setIsHistoty] = useState(false);
	const schemasStart = [
		{
			label: t("felix_ui.admission_time"),
			field: "dateAdmission"
		},
		{
			label: t("felix_ui.adReason"),
			field: "adReason"
		},
		{
			label: t("felix_ui.patient_ID"),
			field: "patId"
		},
		{
			label: t("felix_ui.InsuranceID"),
			field: "insId"
		},
		{
			label: t("felix_ui.adRecievedFrom"),
			field: "adRecievedFrom"
		},
		{
			label: t("felix_ui.doctor"),
			field: "atdDoctor"
		},
		{
			label: t("felix_ui.atdNurse"),
			field: "atdNurse"
		},
		{
			label: t("felix_ui.adStaffId"),
			field: "adStaffId"
		},
		{
			label: t("felix_ui.emgContactName"),
			field: "emgContactName"
		},
		{
			label: t("felix_ui.emgContactPhone"),
			field: "emgContactPhone"
		}
	];
	const schemasEnd = [
		{
			label: t("felix_ui.dcDtime"),
			field: "dcDtime"
		},
		{
			label: t("felix_ui.dcNo"),
			field: "dcNo"
		},
		{
			label: t("felix_ui.trtmtDays"),
			field: "trtmtDays"
		},
		{
			label: t("felix_ui.dcReason"),
			field: "dcReason"
		},
		{
			label: t("felix_ui.isComplication"),
			field: "isComplication"
		},
		{
			label: t("felix_ui.isPathology"),
			field: "isPathology"
		},
		{
			label: t("felix_ui.isDisaster"),
			field: "isDisaster"
		},
		{
			label: t("felix_ui.isRx"),
			field: "isRx"
		}
	];
	const getTitle = t("felix_ui.discharge_history");
	let [patientId, setPatientId] = useState("");
	const [registerDrawer] = useDrawerInner(props.register, data => {
		console.log("打开Drawer", data);
		setPatientId((patientId = data.patientId));
		console.log("patientId	", patientId);
		setIsHistoty(true);
	});

	const [registerHistory] = useFetchHistoryData({
		api: patientSynthesisList,
		contents: "createdTime",
		id: patientId,
		parameter: {
			pageSize: 10,
			pageNo: 1,
			patId: patientId
		},
		contentList: [
			{
				title: t("felix_ui.ipmAdmission"),
				schemas: schemasStart,
				key: "ipmAdmission"
			},
			{
				title: t("felix_ui.ipmDischarge"),
				schemas: schemasEnd,
				key: "ipmDischarge"
			}
		]
	});
	return (
		<BasicDrawer showFooter={false} size="large" {...props} title={getTitle} register={registerDrawer}>
			{isHistory ? <History register={registerHistory}></History> : ""}
		</BasicDrawer>
	);
};

export default DetailDrawer;
